#!/usr/bin/env python2.7
# -*- conding: utf-8 -*-
# @Time : 2020/10/22 9:45
# @Author : ghd
# @file : consumer.py.py
# @Project: python-script 

import json
from kafka import KafkaConsumer

#consumer = KafkaConsumer('test_collect',group_id='handa1',auto_offset_reset='earliest', bootstrap_servers=['10.0.0.31:9092'])
consumer = KafkaConsumer('test_collect',group_id='handa1',auto_offset_reset='lasted', bootstrap_servers=['10.0.0.31:9092'])
#consumer = KafkaConsumer('test_collect1',auto_offset_reset='earliest', bootstrap_servers=['10.0.0.31:9092'])
#consumer = KafkaConsumer('test_collect1',auto_offset_reset='earliest', bootstrap_servers=['10.0.0.31:9092'])
#consumer = KafkaConsumer('test_collect1', bootstrap_servers=['10.0.0.31:9092'])
#print dir(consumer)
#for msg in consumer:
#    recv = "%s:%d:%d: key=%s value=%s" % (msg.topic, msg.partition, msg.offset, msg.key, msg.value)
#    print recv
for msg in consumer:
    print type(msg)
    print type(msg.value)
    data = json.loads(msg.value)
    print type(data)
    print data.keys()
    print data['message']
